"""
区块对象
"""
from utils import block_to_json


class Block:

    def __init__(self, index=0, previous_hash="0", timestamp=0, data="0", data_hash="0", bits="0", nonce=0,
                 miner_ip='0.0.0.0'):
        self.index = index
        self.previous_hash = previous_hash
        self.timestamp = timestamp
        self.data = data
        self.data_hash = data_hash
        self.bits = bits
        self.nonce = nonce
        self.miner_ip = miner_ip

    def get_block_info(self):
        """
        返回区块信息
        :return: 返回区块信息（字典形式）
        """
        return block_to_json(self)

    # def block_to_dict(self):
    #     """
    #     格式化为dict，方便输出到前端
    #     :return: 返回字典
    #     """
    #     temp = dict()
    #     temp['区块索引'] = self.index
    #     temp['前区块hash'] = self.previous_hash
    #     temp['data内容'] = self.data
    #     temp['dataHash'] = self.data_hash
    #     temp['时间戳'] = self.timestamp
    #     temp['难度'] = self.bits
    #     temp['nonce'] = self.nonce
    #     temp['矿机ip'] = self.miner_ip
    #     return temp